package com.acc.store.contorller;

import com.acc.store.common.Result;
import com.acc.store.entity.Supplier;
import com.acc.store.service.SupplierService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/supplier")
@RestController
@Slf4j
@Tag(name = "供应商操作")
public class SupplierContorller {
    @Autowired
    SupplierService supplierService;

@GetMapping("/get/{id}")
@Operation(summary = "供应商回显")
public Result get(@PathVariable Long id){
    Supplier byId = supplierService.getById(id);
    return Result.success(byId);
}
    @PostMapping("/save")
    @Operation(summary = "保存供应商")
    public Result save(@RequestBody Supplier supplier) {
        supplierService.save(supplier);
        return Result.success(null);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除供应商")
    public Result delete(@PathVariable Long id) {
        supplierService.removeById(id);
        return Result.success(null);
    }

    @PutMapping("/update")
    @Operation(summary = "更新供应商")
    public Result update(@RequestBody Supplier supplier) {
        supplierService.updateById(supplier);
        return Result.success(null);
    }

    @GetMapping("/list")
    @Operation(summary = "供应商分页")
    public Result list(@RequestParam Map<String, Object> params) {
        IPage page = supplierService.getPage(params);

        return Result.success(page);
    }
    @GetMapping("/list/all")
    @Operation(summary = "获取列表")
    public Result allList(){
        List<Supplier> list = supplierService.list();
        return Result.success(list);
    }
}
